﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//using Microsoft.Office.Interop;
using System.Net.Mail;
using System.Net;


namespace WindowsFormsApplication3
{
    public partial class MailSend : Form
    {
        MailMessage Mail = new MailMessage();
        SmtpClient smtp = new SmtpClient();
        
        public MailSend()
        {
            InitializeComponent();
        }

        private void BtnMail_Click(object sender, EventArgs e)
        {           
            if (TxtDe.Text == "")
                MessageBox.Show("Por favor Ingrese su cuenta de Hotmail");
            else
            {
                try
                {
                    Mail.From = new MailAddress(TxtDe.Text);
                    Mail.To.Add(TxtPara.Text);
                    Mail.Subject = TxtAsunto.Text;
                    Mail.Body = TxtContenido.Text;
                    SmtpClient s = new SmtpClient("Smtp.live.com");   //"smtp.gmail.com" para gmail     
                    //pop.mail.yahoo.com.ar    port:110
                    //Smtp.googlemail.com      465   no funciona
                    //smtp.mail.yahoo.com.ar   port:587
                    s.Port = 587;
                    s.EnableSsl = true;
                    s.Credentials = new System.Net.NetworkCredential(TxtDe.Text, TxtContraseña.Text);
                    s.Send(Mail);
                    MessageBox.Show("El Mail se ha enviado");
                }
                catch
                {
                    MessageBox.Show("El Mail no se ha enviado");
                }
            }
            TxtContraseña.Text = "";
            TxtPara.Text = "";
            TxtAsunto.Text = "";
            TxtContenido.Text = "";
            TxtContraseña.Focus();
        }

        private void BtnSalir_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}